#include "wdg.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* WWDG handler declaration */
IWDG_HandleTypeDef   iwdgHandle;

void iwdg_resume_check(void)
{
  
}

void iwdg_reset_value_config(uint32_t data)
{
     uint32_t reload_value;
     
     /*
      * 40kHz / 256 = 156hz (~6.4ms);
      */
     reload_value = (data / 6);
     if(reload_value > 0x0fff)
         app_fault_handle(APP_WDG_ERROR);
     
     iwdgHandle.Instance = IWDG;
     iwdgHandle.Init.Prescaler = IWDG_PRESCALER_256;
     iwdgHandle.Init.Window = IWDG_WINDOW_DISABLE;
     iwdgHandle.Init.Reload = reload_value;
     
     if(HAL_IWDG_Init(&iwdgHandle) != HAL_OK)
     {
         app_fault_handle(APP_WDG_ERROR);
     }
     
     /*##-3- Start the IWDG #####################################################*/ 
     if(HAL_IWDG_Start(&iwdgHandle) != HAL_OK)
     {
       app_fault_handle(APP_WDG_ERROR);
     }

}

void HAL_IWDG_MspInit(IWDG_HandleTypeDef *hiwdg)
{
      /* Enable the IWDG peripheral */
      __HAL_IWDG_START(hiwdg);
}

void iwd_feed(void)
{  
    /* Reload IWDG counter with value defined in the reload register */
     
    if(HAL_IWDG_Refresh(&iwdgHandle) != HAL_OK)
    {
         while(1);
    }
      
}



